package com.example.download.utils

import java.util.LinkedList

/**
 * 支持顺序下载
 */
class DownLoadHelper {
    private var mFieldPath: String? = null
    private var mUrls: List<String>? = null


    class Builder {

        private var fieldPath: String? = null
        private var urls: List<String>? = null
        fun setFieldPath(fieldPath: String):Builder {
            this.fieldPath = fieldPath
            return this
        }

        fun setUrls(urls: List<String>):Builder {
            this.urls = urls
            return this
        }

        fun builder() = DownLoadHelper().apply {
            this.mFieldPath = fieldPath
            this.mUrls = urls
        }

    }

    private var linkedList: LinkedList<LoadTask>? = null
    fun enqueue() {
        mUrls?.forEach {
            linkedList?.add(LoadTask(it))
        }
        if (DowLoadUtils.isDownLoading) return
        val task =  linkedList?.first
        task?.let {
            mFieldPath?.let { it1 ->
                DowLoadUtils(it.url, it1, onSuccessListener = { file, i, s ->

                }, onFailureListener = {

                })
            }
        }
    }
}